// Keyboard.cpp: implementation of the Keyboard class.
//
//////////////////////////////////////////////////////////////////////

#include "Keyboard.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Keyboard::Keyboard()
{
  /* Foe each key set NOT PRESSED... */
  for ( int i = 0 ; i <   512 ; i++ )
	{
	this->keyIsDown[ i ] = 0;
	}
}

Keyboard::~Keyboard()
{

}

void Keyboard::read(int key, int updn, int x, int y)
{
this->keyIsDown [ key ] = (updn==PW_DOWN) ;
}

int Keyboard::read()
{
#ifdef CONSOLE
 #ifdef DEBUG  
 printf("KEY PRESSED: ");
 #endif
#endif
  for ( int i = 0 ; i < 512 ; i++ )
    if ( this->keyIsDown [ i ] )
    {
      if(i == 27) return 0;
      #ifdef CONSOLE
       #ifdef DEBUG  
       fprintf ( stderr, "%c ", i ) ;
       #endif
      #endif
    }
#ifdef CONSOLE
 #ifdef DEBUG  
  fprintf ( stderr, "\n" ) ;
 #endif
#endif
  return 1;
}

int Keyboard::isWorking()
{
	// Keyboard supposed to be present...
	return 1;
}

char* Keyboard::getKeyIsDown()
{
	return this->keyIsDown;
}

int Keyboard::isPressed(int key)
{
    return this->keyIsDown[key];
}

int Keyboard::isPressedAny()
{
  for ( int i = 0 ; i < 512 ; i++ )
    if ( this->keyIsDown [ i ] )
    {
         return 1;
    }
return 0;    
}

